<?php
session_start();
require_once( 'otherpay_db.php' );
 
$type = new M_Otherpay();
$user_id = $_SESSION['userid'];

if (isset($_POST['m'])  &&  $_POST['m']!=""){
    if ($_POST['m']== 'load'){
	  $month = $_POST['month'];
	  $name = $_POST['name'];
	  $type_other = $_POST['type'];
      $result=$type->loadData($month,$name, $type_other);
      $rows=$type->getRowCount();
      $i=1;
      $html="";
      if ($rows>0){
           $data = array();
            while($row = $result->FetchRow()){
               $data[] = array(0,$row['id'],$row['type_id'],$row['monthpay'], $row['type'], $row['name'], number_format( $row['amount'] ,0,'',',')) ;
            }
        }else{
			$data = array();
        }
    
        $arr = array('aaData'=>$data);
        
        echo json_encode($arr);
      
    }else if ($_POST['m']=='add'){
        $ar = array();
		list($d,$m,$y) = explode("/", $_POST['month']);
		$ar['name']=  $_POST['name'];
		$ar['type'] = $_POST['type'];
		$ar['month_pay']=  $y.'/'.$m.'/'.$d;
		$ar['amount']=  $_POST['amount'];
		$ar['createdate'] =date( "Y/m/d H:i:s" );
		$ar['createby'] = $user_id;
		 
		$id=$type->InsertData($ar);
		
    }else if ($_POST['m']=='edit'){
		$ar = array();
		list($d,$m,$y) = explode("/", $_POST['month']);
		$ar['name']=  $_POST['name'];
		$ar['month_pay']=  $y.'/'.$m.'/'.$d;
		$ar['type'] = $_POST['type'];
		$ar['amount']=  $_POST['amount'];
		$ar['updatedate'] =date( "Y/m/d H:i:s" );
		$ar['updateby'] = $user_id;
		 
		$strcipt = $type->updateData($_POST['id'],$ar);
		// echo json_encode($strcipt);
	}
	else if ($_POST['m']=='del'){
         $id=$_POST['id'];
		 
		 $type->deleData($id);
		 
    }/// Age Criteria
	    
}else{
}
 
?>